package com.qf.springmq.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {

    @Bean
    public RedisTemplate redisTemplate(RedisConnectionFactory fac){

        RedisTemplate<String,Object> template = new RedisTemplate<>();
        //设置链接工厂
        template.setConnectionFactory(fac);
        //key的序列化
        template.setKeySerializer(new StringRedisSerializer());
        //volue的序列化
        template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
        //设置hash数据结构 key的序列化
        template.setHashKeySerializer(new StringRedisSerializer());
        //设置hash数据结构 value的序列化
        template.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
        return template;
    }


}
